package com.ecjtu.stadiumre_servations.utils;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

public class LocalDateTimeSplitterUtils {
    public static List<LocalDateTime[]> splitIntoHourlyIntervals(LocalDateTime start, LocalDateTime end) {
        List<LocalDateTime[]> intervals = new ArrayList<>();
        LocalDateTime current = start;
        while (current.isBefore(end)) {
            LocalDateTime next = current.plus(1, ChronoUnit.HOURS);
            // 如果下一个时间点超过了结束时间，则将结束时间作为该时间段的结束
            if (next.isAfter(end)) {
                next = end;
            }
            intervals.add(new LocalDateTime[]{current, next});
            current = next;
        }
        return intervals;
    }
}
